package com.itheima.类加载与反射.反射.案例四;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class 反射Math类 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
        //获取类对象
        Class ac = Class.forName("java.lang.Math");
        //获取一个私有构造方法
        Constructor con = ac.getDeclaredConstructor();
        //设置:强制暴力反射
        con.setAccessible(true);
        //获取Math对象
        Math math = (Math) con.newInstance();
        //调用方法,打印对象
        int random = (int) (math.random() * 100 + 1);
        System.out.println("random=" + random);


    }
}
